package com.allwees.sender;

import com.allwees.bs.core.model.user.entity.MessageModel;
import com.allwees.core.common.util.json.JsonUtil;
import com.allwees.sender.message.MessageSaveDao;
import org.springframework.util.CollectionUtils;

import java.util.Map;

public class MessageSender {

	private MessageSaveDao messageDao;

	public void send(String user, String title, String content, String link, String imgUrl, Map<String, String> params) {
		MessageModel message = new MessageModel();
		message.setMarkread(false);
		message.setUserUuid(user);
		message.setTitle(title);
		message.setText(content);
		message.setImageUrl(imgUrl);
		message.setLink(link);
		message.setParams(toParamJson(params));
		messageDao.saveMessage(message);
	}

	private String toParamJson(Map<String, String> params){
		if (CollectionUtils.isEmpty(params)) {
			return null;
		}
		return JsonUtil.toJson(params);
	}

	public void setMessageDao(MessageSaveDao messageDao) {
		this.messageDao = messageDao;
	}
}
